<?php
//连接数据
function link_db($DB){
	try {
		return new PDO('mysql:host='.$DB['HOST'].';dbname='.$DB['NAME'],$DB['USER'],$DB['PASS'],array(PDO::ATTR_PERSISTENT => true));
	} catch(Exception $e) {
		die('Connect Failed Message: ' . $e->getMessage());
	}
}
//查询
function select($sql,$DB){
    $result = link_db($DB)->query($sql);
    return $result->fetchAll(PDO::FETCH_ASSOC);
}

//插入
function  insert($sql,$DB){
	$db = link_db($DB);
    $result = $db->exec($sql);
    return $db->lastInsertId();
}

//update
function  update($sql,$DB){
    return link_db($DB)->exec($sql);
}

//update
function  delete($sql,$DB){
    return link_db($DB)->exec($sql);
}
